fixed.
refactored.
added instance check to avoid possible errors