Cleaned up code. Now validates data.