fixing logical bugs. not done yet