fixed all bugs

code is cleaned an working correctly.