Can't dynamically allocate on the stack!

New up some memory and then free it at the end
Add the round function for Windows

Also, stop using floor and ceil for integer division operations.
This needs to be tested by @nontas!