fixed many bugs, it does compile