Style fixes (indention, whitespace, grouping of function argument blocks)
commenting
fix: as the comment says, the function should be able to handle multible calls
added helper function to remove all remaining data
fix: added missing decrement of shutdown function counter
replaced non-DRY core with macro
Merge branch 'core-cleanup' into core