Make board size function more robust