organised code and added base class