Finished complete rewrite except target tracking and array management.