Add clear button, refactor code