refactored code, fixed scope, added getters and setters