Began work on Android port, general cleanup

Began working on Android port, and some code refactoring.