added my external code
fixed some warnings, bugs, improved code formatting etc.
minor