added functions and cleaned up