added a nil statement for invalid input
fixed merge changes