First part finished, needs refactoring