fixed errors some logic errors and tested all functions