remove unused code and avoid nils