several bugs fixed, several functions added