Added search function, various fixes
Removed main
Enable debug messages if DEBUG is defined