Code cleanup

Cleaned the code and use directives for dom manipulation.