Code cleanup

Some code cleanup for better integration with other applications