Added cleanup handlers. (mostly) cleaned up memory usage (mostly). tile selection now works (mostly).