Formatted and cleaned up code