Gave better names to the functions, cleaned up.