Fixed naming, alignment and made some variables local