fixing some bugs and adding timer