reorganize some code related to controller