[IMP] improved code and fixed some issues.