Restoring correct code (before bug with selected_entity stuff was introduced)