Sort functionality

closes #276