bug fixes with accessing nil