Reorganized bluetooth and layout code for more modularity.