fixed bugs and added timer