added some return statements and finished refactor