fix nilclass errors