fixed syntax error and added sanity checking.