Wow, this is very hard. It took me some time to at least make some progress. The game was very slow at the beginning and suddenly became a lot faster and more playable. Not sure if this is intended, otherwise your might want to look into this, maybe you do not use real time for your calculations.