Otapi checks 2

Continue of #274 
This PR fix all OTAPI methods to return error code instead of crash the process. There are also commits that clean up code and use constant OT_ERROR instead of magic number -1.