Fixed indentation and restructured code