Correct method definition's order and better error code
Add buffer size checks before set