Added index table lookup and fixed sorting options to work with join