improved design.
fixed some minor bugs.