refactored velocity code