Fixed so that elements is added by it's priority

A bit ugly, could probably be done in a nice fashion.