added cleared flag, refactored