refactored
fixed some code issues