added level recognition, still tends to be off by about a bin size