fixed some randomly occuring bugs