Simplyfied the code as much as possible.