Yay, working but ugly code :-(