Indentation and logic fixes