some cleanup of redundant code, creating sort array