code cleaned and reindented
fixed problems with click events