Fixed indentation and integrated some prewritten code (not sure if it's correct)