fixed the bug with alert exception on refrefresh, also some refactoring