add stats, fix errors, slight cleanup