Refactor code / Allow for callback functions