moved some code of lines to base class, refactor code to be more readable.