remove trailing spaces
added defer function for async execution of layout sensitive methods
resolve #287