Code refactory

avoiding too many variable and byte conversions