Sorted out some bugs