some bugs fixed, new routines