Cleaned up code

- added validation
- checking for existing values