added some extra checks to ensure theres less errors