add validation of input buffer