changed constructor and added function