Refactersing & bug fix