Modified to clean up code