Refacoring code