Cleaned up and reformatted code