changed data structure of required
tiny optimization
added tests