refactared some codes