reformat code and bug fix to custom view code