Code clean up, add some UI validation logic