fixed a bug and a syntax error. Should have tested before the commit