Removed extra if as suggested by @hvelarde