fixed bugs and input handling