Completed, but with bugs -- cost & profit functions returning incorrect values