completed functions

Seems to be complete, though simplifying this spaghetti will be a high priority