added a working controller spec and fixed some bugs in the code