Simplified some things and fixed a bug