Removed some duplicate code and minor cs-fixes