Remove some duplicates in code, minor fixes