Added username support and cleaned up code