Fix for #9
Various optimizations
Separate ghost calculation and drawing
Various refactorings