elsif instead of nested ifs, use next! instead of type togglng count, moved now assignment outside of if