fixing some bugs, removing the old code