Cleaned up the code to make it more consistent in style