added handler logic and nasty gui code