Simplified interface, fixed some bugs.