moved much logic up to the application level.  It compiles