Updated to not rely on static values. Added comments.