Added null checking and replaced ifs with switch.