Needs cleanup, but works as intended