Added some code dealing with the corner cases