All working, needs refactoring