Code refactoring

Remove common part of if..elsif..end in meauures and add it below the condition.