API changes to include username and also some refactoring