Fixed a few bugs and improved prioritization