Implement derivative framework and some general fixes.