There is a lot of duplicate code...