added function

added functions, cleaned up code