Implemented all main functionality