updated functions to be more python-like, some refactoring