added sort by type option and minor fixes