fixing some bugs - badly