Beautified code according to Linux and C style. Kept original for personal use