made a bunch of changes and added a bunch of helper functions