Added a necessary null check
Added null values test and removed some useless lines