Cleaned up indentation and minor refactoring