Indentation and code flow fixed