Added user functions

added various functions, cleaned up code.