Added basic UI, safety checks

Also refactored code for smaller size, efficiency, and readability.