move logic from views