Make classes generic and remove duplication [DO NOT MERGE]