formatted and cleaned up code