Added some new features and patched some bugs

New:
- Packet length calculation
- Improved logging mechanism
- Some bugfixes