Finished code refactor. All functions working as expected.