modularize & fix