codestyle
added try-catch and updating bufferpos for more stability