refactored the code a bit
fixed the indentation of the function