Removed some code repetitions and decreased buffer size