Cleaned up some of the functions