Refactored to enable preview to work