Same functionality rewritten using boost library.