Finished API prediction.
Some refactoring.