fixed bug, several improvements