Completed justify function