Code cleanup & external mode