fixed some really fucking subtle bugs