Usage of switch instead of if
Use plen and flen instead of hardcoded constants