Using Boost, cleaned and simplified code