refacoring bug fixed