Cleaned up the back end code