Refactoring + Minor bugfix