Fixed warnings from compiler and a logic error and now it all works!