Fix nil reference exception