Working but needs refactoring