corrected function writing by spltting it up in a method with accesability, and one without.