fixed many bugs with previous commit