modularized and switched to php