Changed initialization code to be more dynamic