Refactor mapBoard and a few other functions