Modified to include additional checks and work with urls