Code cleanup and corpse opening bug fix

Made the code easier to understand and