check around elements null value and code cleanup