lots of fixes and improvments

created directives for code reuse