moved if statement to inside if statement
- prevents null entries in database