code raarrangment and type fixes