modularize model_layer and update tests