Fixed some duplication errors, cleaned code