Code Refactor

Issue #348