cleaning up some stuff with the directives, adding some basic error handlings