cleaned code. Added application preference to store username