Indentation and logic bugfixes