rearranged code to have better inheritance