refactored initialize method, bug fix