Refactored frondend to match backend. Tested and working.