finished, needs bug fixes and refactoring