Refactored somewhat
Bug