Bug fixes for v0.18.0

This includes two bug fixes suitable for v0.18.0:
* Reducing the likelyhood of memory leaks
* Fixing pixel calculations causing a ArrayIndexOutOfBoundsException