added new functions and cleaned up previous code