Use limits.h for the buffer
Cleaned code formatting, added comments
Saner mamory handling. Now the buffer is allocated only one time