Fully functional code, buggy. Refactor needed.