Added bug checking
Braces fixed
edited error work