minor modifications and bugs fixed