fix null check and compacted/calrified code