fix #104, better algorithm
fix #110, added empty section