Added ending, needs refactoring