added functions and more code