Move method to util class, refine code