Fixed some pretty bad bugs