cleaned up the code something