sorted out some bugs