Fixed some high-prioritiy bugs. Algorithm now works.