refactored most js