Implemented local switching and formated code