Fixed some problems (may have introduced others)