API reorganized again. Fixed many bugs.