now with more functional programming inside