Minor changes

Added a safety check and removed some redundant code