Fixed duplication of code