Branch selection from preferences

Branch selection from preferences
LOT of housekeeping
Database changed to store all the new values for branch
Authentication token problem and json parsing problem also fixed.
NPE when accessing the database fixed.