fixed some bugs.
first draft of direct version