cleaned up and renamed some functions