Added most of the code needed for decode stage