some refactoring, improvements to onclick