Significant code cleanup
Implemented cleaner methods from Android port
Fixed up bad indentation