Use switch statement for cleaner code and add some doc