modularize some code