fixed eqs. and cleaned up a bit of code