Remove obsolete code and fix condition