What if the 'happy ending' wasn't what he wanted to happen? (spoilers)
Think about what the professor had said. He had made the machine in hopes of it bringing peace and making the world better. He put all of his traits into the machine, but realized he forgot something important, his "soul." They showed him being ripped away from the machine, so he apparently was no longer able to gain access to it. He later put his "soul" into the dolls, and kept the mechanism to power the machine back up in the office where the dolls could find it. Once the machine was powered back up, it went around collecting the "souls" of all of the dolls.
So, putting all of that together, what if the scientist's original plan was for the dolls to transport his "soul" to the machine, making it - at least as he assumed - whole, and a force for good?